<%= render(:partial => 'shared/header') %>
<%#=debug @params %>
<%#=debug @options %>
<%#=debug @list_rows[0][:id] %>
<%= render(:partial => 'shared/list_body') %>
<%
	@paging = false
	if @list_rows.length == 1 and @scaffold_model.has_children?
		parent_options = @options
		if not @options[:id].nil?
			parent_id = @options[:id]
		elsif not @options[:parent_id].nil?
			parent_id = @options[:parent_id]
		else # if filter_by selects just one row
			parent_id = @list_rows[0][:id]
		end
		parent_columns = num_columns_in_list + 1
		parent_model = @scaffold_model
		@scaffold_model.children.each do |model|
	 		scaffold_model = model.to_s.pluralize.singularize.camelize.constantize
			if params[:crud_action]
				model_action = params[:crud_action]
				model_id = params[:crud_id]
			else
				model_action = "list"
				model_id = nil
			end
			scaffold_model_assoc_name = @scaffold_model.to_s.underscore.to_sym
			parent_id_column_name = "#{@scaffold_model.to_s.tableize.singularize}_id"
			parent_id_column_name = model.reflect_on_association(scaffold_model_assoc_name).primary_key_name unless model.reflect_on_association(scaffold_model_assoc_name).nil?
 			@options = @options.merge(
									:model => scaffold_model, 
									:parent_model => @scaffold_model, 
									:parent_id => parent_id, 
									:parent_id_column_name => parent_id_column_name,
									:scaffold_model => scaffold_model,  
									:scaffold_id => [ @options[:scaffold_id], @options[:id], scaffold_model].join("-"), 
									:layout => false)
%>
<tr id="<%= element_row_id(@options) %>">
  <td class="child" colspan="<%= parent_columns %>">
		<%#=debug model.reflect_on_all_associations %>
		<%#= debug @scaffold_model.to_s.underscore.to_sym %>
		<%= render_component :action => model_action, :id => model_id, :params => @options %>
	 </td>
</tr>
<%
		end
		@options = parent_options
  end
%>
<%= render(:partial => 'shared/footer') %>
